package cn.ylz.ylmall.account.dao.persist.repository.impl;

import cn.ylz.ylmall.account.dao.persist.repository.IUserRoleRepository;
import cn.ylz.ylmall.account.dao.persist.mapper.UserRoleMapper;
import cn.ylz.ylmall.account.pojo.entity.UserRole;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public class UserRoleRepositoryImpl implements IUserRoleRepository {
    @Autowired
    private UserRoleMapper userRoleMapper;

    @Override
    public int insertBatch(List<UserRole> userRoleList) {
        int count = userRoleMapper.insertBatch(userRoleList);
        return count;
    }

    @Override
    public int deleteByUserId(Long userId) {
        QueryWrapper<UserRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        return userRoleMapper.delete(queryWrapper);
    }

    @Override
    public int deleteByRoleId(Long roleId) {
        QueryWrapper<UserRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_id", roleId);
        return userRoleMapper.delete(queryWrapper);
    }
}
